package cn.edu.sjtu.se.dslab.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import cn.edu.sjtu.se.dslab.component.data.DomainEntity;
import cn.edu.sjtu.se.dslab.component.method.MethodToDomain;
import cn.edu.sjtu.se.dslab.dao.IBaseDao;
import cn.edu.sjtu.se.dslab.dao.IMethodToDomainDao;

@Repository("methodToDomainDao")
public class MethodToDomainDaoImpl implements IMethodToDomainDao {

	
	@Resource(name = "baseDao")
	private IBaseDao<MethodToDomain> baseDao;
	
	@Override
	public void save(MethodToDomain methodToDomain) {
		// TODO Auto-generated method stub
		baseDao.save(methodToDomain);
	}

	@Override
	public void update(MethodToDomain methodToDomain) {
		// TODO Auto-generated method stub
		baseDao.update(methodToDomain);
	}

	@Override
	public MethodToDomain queryById(long id) {
		// TODO Auto-generated method stub
		return baseDao.queryById(MethodToDomain.class, id);
	}

	@Override
	public List<MethodToDomain> queryByDomainEntity(DomainEntity entity) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer();

		// 拼接sql语句
		hql.append("from MethodToDomain m where ");
		hql.append(" m.entity.id=");
		hql.append("" + entity.getId());
		return baseDao.query(hql.toString());
	}

}
